package dt.board.review;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.Reader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

public class viewAction extends ActionSupport implements SessionAware {
	private Map session;
	public static Reader reader;
	public static SqlMapClient sqlMapper;

	private boardVO paramClass = new boardVO(); // �Ķ���͸� ������ ��ü
	private boardVO resultClass = new boardVO(); // ���� ��� ���� ������ ��ü

	private int currentPage;

	private int no;
	private String password;
	private int BoardFlag = 5;

	private InputStream inputStream;
	private String contentDisposition;
	private long contentLength;

	private int adminCheck; // 더미 아이디 설정
	private String adminId;

	// ����
	public viewAction() throws IOException {

		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); // sqlMapConfig.xml
																	// ������
																	// ����������
																	// �����´�.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); // sqlMapConfig.xml��
																	// ������
																	// �����
																	// sqlMapper
																	// ��ü ��.
		reader.close();
	}

	// �󼼺���
	public String execute() throws Exception {

		// �ش� ���� ��ȸ�� +1.
		paramClass.setNo(getNo());
		sqlMapper.update("review.updateReadHit", paramClass);

		// �ش� ��ȣ�� ���� �����´�.
		resultClass = (boardVO) sqlMapper.queryForObject("review.selectOne",
				getNo());

		if (session.get("id") != null) {

			if (session.get("id").equals("admin1")) {

				adminCheck = 1;

			}
		}

		return SUCCESS;
	}

	// ��й�ȣ üũ ��
	public String checkForm() throws Exception {

		return SUCCESS;
	}

	// ��й�ȣ üũ �׼�
	public String checkAction() throws Exception {

		// ��й�ȣ �Է°� �Ķ���� ����.
		paramClass.setNo(getNo());
		paramClass.setPassword(getPassword());

		// ���� ���� ��й�ȣ ��������.
		resultClass = (boardVO) sqlMapper.queryForObject(
				"review.selectPassword", paramClass);

		// �Է��� ��й�ȣ�� Ʋ���� ERROR ����.
		if (resultClass == null)
			return ERROR;

		return SUCCESS;
	}

	public String adminCheckAction() throws Exception {
		
		
		if (session.get("id").equals("admin1") && getPassword().equals("delete")) {
		
		
		
			 

			return SUCCESS;

		} else {

			return ERROR;
		}

	}

	public boardVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(boardVO paramClass) {
		this.paramClass = paramClass;
	}

	public boardVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(boardVO resultClass) {
		this.resultClass = resultClass;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getContentDisposition() {
		return contentDisposition;
	}

	public void setContentDisposition(String contentDisposition) {
		this.contentDisposition = contentDisposition;
	}

	public long getContentLength() {
		return contentLength;
	}

	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getBoardFlag() {
		return BoardFlag;
	}

	public void setBoardFlag(int boardFlag) {
		BoardFlag = boardFlag;
	}

	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public int getAdminCheck() {
		return adminCheck;
	}

	public void setAdminCheck(int adminCheck) {
		this.adminCheck = adminCheck;
	}

	public String getAdminId() {
		return adminId;
	}

	public void setAdminId(String adminId) {
		this.adminId = adminId;
	}
}